<?php
/* @var $form CActiveForm */
/* @var $comment Comment */
/* @var $allComment Comment[] */
/* @var $tags ImageTag[] */
/* @var $model Image */
/* @var $sameImages Image[] */
/* @var $users User[] */
//echo CHtml::link('Save Image', array('collection/saveimage', 'id' => $model->id)) . '<br>';
//echo '<img width="350px" src="' . Yii::app()->baseUrl . '/upload/user/' . $model->userCreated->id . '/images/' . $model->img_url . '" /><br>';
//if (!Yii::app()->user->isGuest) {
//    if ($model->user_created == Yii::app()->user->id) {
//        echo '<a href="' . Yii::app()->createUrl('image/addtags', array('id' => $model->id)) . '">Add Tags</a>';
//    }
//}
//if ($tags != null && sizeof($tags) > 0) {
//    echo '<h2>Tags:</h1><br/>';
//    foreach ($tags as $tag) {
//        echo'<b>Item:</b> ' . $tag->item->name . '<br/>';
//        echo'<b>Thương hiệu:</b> ' . $tag->brand . '<br/>';
//        if (!Yii::app()->user->isGuest) {
//            if ($model->user_created == Yii::app()->user->id) {
//                echo '<a href="' . Yii::app()->createUrl('image/removetag', array('id' => $tag->id)) . '">Remove Tags</a><br/>';
//                echo '<a href="' . Yii::app()->createUrl('image/edittag', array('id' => $tag->id)) . '">Edit Tags</a><hr/>';
//            }
//        }
//    }
//}
//if ($allComment != null && sizeof($allComment) > 0) {
//    echo '<h2>Comments</h2>';
//    foreach ($allComment as $cm) {
//        echo '<b>' . $cm->user->fullname . '</b><br>';
//        echo 'Lúc : ' . Format::timeAgo($cm->comment_at,'Y-m-d H:i:s') . '<br>';
//        echo CHtml::encode($cm->content) . '<br><hr>';
//    }
//}
//
?>
<script type="text/javascript">
    function follow(id) {
        $.ajax({
            url: "<?php echo Yii::app()->createUrl('user/follow') . '?id='; ?>" + id,
            type: 'GET',
            success: function() {
                $("#user_" + id).remove();
            }
        });
        return false;
    }
</script>
<!-- main home -->
<div id="main">
    <div id="main_content" class="page_view">
        <!-- view -->
        <!-- col left -->
        <div class="col_left">
            <div class="c_l_top">
                <div class="c_l_t_avatar d_avatar">
                    <a href="<?php echo Yii::app()->createUrl('user/view', array('username' => $model->userCreated->username)) ?>"><img class="d_avatar" src="<?php echo Yii::app()->baseUrl . '/upload/user/' . $model->user_created . '/avatar/' . $model->userCreated->avatar; ?>" border="0" /></a>
                </div>
                <div class="c_l_t_info">
                    <a class="member_name dib" href="<?php echo Yii::app()->createUrl('user/view', array('username' => $model->userCreated->username)) ?>"><?php echo $model->userCreated->fullname; ?></a> - <h1 class="dib">The Essential: Denim Short</h1>
                    <?php
                    if ($imageInCollection != null) {
                        ?>
                        <p>Bộ sưu tập : <a href="<?php echo Yii::app()->createUrl('collection/view', array('id' => $imageInCollection->collection_id)) ?>" title="<?php echo $imageInCollection->collection->name ?>"><?php echo $imageInCollection->collection->name ?></a></p>
                        <?php
                    }
                    ?>

                    <p><span class="time sprites"></span> <?php echo Format::timeAgo($model->created_at, 'Y-m-d H:i:s'); ?></p>
                </div>
                <div class="c_l_t_share">
                    <div class="content">
                        CHIA SẺ
                        <p>
                            <a href="#" title="Facebook" class="share_icons share_icons_fb"></a>
                            <a href="#" title="Twitter" class="share_icons share_icons_tw"></a>
                            <a href="#" title="Tumblr" class="share_icons share_icons_tr"></a>
                            <a href="#" title="Pinterest" class="share_icons share_icons_pin"></a>
                        </p>
                        <p><img src="<?php echo Yii::app()->baseUrl . '/images/like_demo.png'; ?>" border="0" /></p>
                    </div>
                </div>
                <div class="clr"></div>
            </div>
            <div class="c_l_main">
                <div class="c_l_m_photo">
                    <?php
                    if ($tags != null && sizeof($tags) > 0) {
                        $i = 0;
                        foreach ($tags as $tag) {
                            $position = json_decode($tag->position);
                            $i++;
                            ?>
                            <div class="pic_tag" style="top: <?php echo $position->x; ?>px; left: <?php echo $position->y; ?>px;"><a id="tag_<?php echo $i; ?>"><?php echo $i; ?></a></div>
                            <div class="pic_desc" id="position_<?php echo $i; ?>"><div class="tag_content"><span><?php echo $i; ?></span><?php echo $tag->item->name; ?><div class="tag_shop"><div class="sprites shop_icons"></div><a href="#" title="Fchic Shop">Fchic Shop</a></div></div></div>
                            <?php
                        }
                    }
                    ?>
                    <img src="<?php echo Yii::app()->baseUrl . '/upload/user/' . $model->userCreated->id . '/images/' . $model->img_url; ?>" border="0" />
                </div>
                <div class="c_l_m_info">
                    <div class="c_l_m_product">
                        <?php
                        if ($tags != null && sizeof($tags) > 0) {
                            $i = 0;
                            foreach ($tags as $tag) {
                                $position = json_decode($tag->position);
                                $i++;
                                ?>
                                <p><?php echo $i . ' . ' . $tag->item->name; ?><a href="#" title="Fchic shop"> - Fchic shop</a></p>
                                <?php
                            }
                        }
                        ?>
                    </div>
                    <div class="c_l_m_i_stats">
                        <div class="c_l_m_i_like">
                            THÍCH
                            <p><span class="sprites like_icon"></p>
                            <p><?php echo $model->like_cnt; ?></p>
                        </div>
                        <div class="c_l_m_i_comment">
                            BÌNH LUẬN
                            <p><span class="sprites comment_icon"></p>
                            <p><?php echo sizeof(Comment::model()->findAll('image_id=:id', array(':id' => $model->id))); ?></p>
                        </div>
                        <div class="clr"></div>
                    </div>
                    <div class="clr"></div>
                </div>
                <?php
                if ($imageInCollection != null && sizeof($sameImages) > 0) {
                    ?>
                    <!-- collection --->
                    <div class="c_l_m_incollect">
                        <div class="c_l_m_other">
                            <ul id="other_pic" class="jcarousel-skin-tango">
                                <?php
                                foreach ($sameImages as $img) {
                                    ?>
                                    <li><a href="<?php echo Yii::app()->createUrl('image/view', array('id' => $img->id)) ?>" title="<?php echo $img->title; ?>"><img height="114px" title="<?php echo $img->title; ?>" border="0" src="<?php echo Yii::app()->baseUrl . '/upload/user/' . $img->userCreated->id . '/images/' . $img->img_url; ?>" alt="<?php echo $img->title; ?>" /></a></li>
                                    <?php
                                }
                                ?>
                                <li><a href="<?php echo Yii::app()->createUrl('collection/view', array('id' => $imageInCollection->collection_id)) ?>" class="c_l_m_o_link"><img border="0" src="<?php echo Yii::app()->baseUrl . '/images/bst.jpg'; ?>" alt="" /></a></li>
                            </ul>
                        </div>
                        <div class="c_l_m_o_name">
                            <span>CÙNG</span> <p>BỘ SƯU TẬP</p>
                            <a href="<?php echo Yii::app()->createUrl('collection/view', array('id' => $imageInCollection->collection_id)) ?>" class="c_l_m_o_link">Xem tất cả (<?php echo sizeof($sameImages) ?> ảnh)</a>
                        </div>
                    </div>
                    <?php
                }
                ?>
                <!-- comment -->
                <div class="c_l_m_comment">
                    <h1>BÌNH LUẬN</h1>
                    <div class="c_l_m_c_tabs">
                        <ul class="idTabs">
                            <li><a href="#fc_cm" class="selected">Fchic</a></li>
                            <li><a href="#fb_cm">Facebook</a></li>
                        </ul>
                    </div>
                    <div class="clr"></div>
                    <div class="c_l_m_c_content">
                        <div id="fc_cm" style="display: none;">
                            <?php if (Yii::app()->user->id != null) {
                                ?>
                                <div class="fc_list">
                                    <?php
                                    $form = $this->beginWidget('CActiveForm', array(
                                        'id' => 'comment-form',
                                        'action' => array(
                                            'image/comment/' . $model->id
                                        ),
                                        'enableClientValidation' => true,
                                        'clientOptions' => array(
                                            'validateOnSubmit' => true
                                        )
                                    ));
                                    ?>
                                    <div class="d_avatar mr10 fll"><a href="#"><img src="<?php echo Yii::app()->baseUrl . '/upload/user/' . Yii::app()->user->id . '/avatar/' . User::model()->getUserById(Yii::app()->user->id)->avatar; ?>" border="0" /></a></div>
                                    <div class="fcl_input fll">
                                        <?php echo $form->textArea($comment, 'content', array('placeholder' => 'Bình luận...')); ?>
                                    </div>
                                    <div class="clr"></div>
                                    <div class="flr">
                                        <?php echo CHtml::submitButton('Đăng bình luận', array('class' => 'gr_btn_normal')); ?>
                                    </div>
                                    <div class="clr"></div>
                                    <?php $this->endWidget(); ?>
                                </div> 
                                <?php
                            } else {
                                echo 'Bạn hãy <b>' . CHtml::link('đăng nhập', array('user/login')) . '</b> để đăng bình luận.';
                            }
                            ?> 
                            <?php
                            if ($allComment != null && sizeof($allComment) > 0) {
                                foreach ($allComment as $cm) {
                                    ?>
                                    <div class="fc_list">
                                        <div class="d_avatar mr10 fll"><a href="<?php echo Yii::app()->createUrl('user/view', array('username' => $cm->user->username)) ?>"><img src="<?php echo Yii::app()->baseUrl . '/upload/user/' . $cm->user->id . '/avatar/' . $cm->user->avatar; ?>" border="0" /></a></div>
                                        <div class="fcl_info fll">
                                            <a href="#" class="member_name"><?php echo $cm->user->fullname; ?></a>
                                            <p class="fcl_i_cm"><?php echo CHtml::encode($cm->content); ?></p>
                                            <div class="fcl_i_action"><?php echo Format::timeAgo($cm->comment_at, 'Y-m-d H:i:s'); ?></div>
                                        </div>
                                        <div class="clr"></div>
                                    </div>
                                    <?php
                                }
                            } else {
                                echo 'Chưa có bình luận nào.';
                            }
                            ?>
                        </div>
                    </div>
                    <div class="clr"></div>
                </div>
                <!-- / comment -->
            </div>
        </div>
        <!-- / col left -->
        <!-- col right -->
        <div class="col_right">
            <div class="col_right_trend">
                CÙNG PHONG CÁCH
                <h1>" Đường phố "</h1>
            </div>
            <!-- collect -->
            <div class="col_right_collect">
                <div class="c_r_c_li">
                    <div class="c_r_c_li_thumb"><a href="collection.html" title="Xinh tươi cùng gió"><img src="<?php echo Yii::app()->baseUrl . '/images/demo/collect_1.jpg'; ?>" border="0" title="Xinh tươi cùng gió" alt="Xinh tươi cùng gió" /></a></div>
                    <div class="c_r_c_li_info">
                        <a href="#" title="Xinh tươi cùng gió"><h1>Xinh tươi cùng gió</h1></a>
                        <a href="#" title="Lyzmary"><h2>Lyzmary</h2></a>
                        <p><span class="sprites like_icon"></span>322</p>
                        <p><span class="sprites collection_icon"></span>16 ảnh</p>
                    </div>
                </div>
                <div class="c_r_c_li">
                    <div class="c_r_c_li_thumb"><a href="collection.html" title="Blue Cheetah Print"><img src="<?php echo Yii::app()->baseUrl . '/images/demo/collect_2.jpg'; ?>" border="0" title="Blue Cheetah Print" alt="Blue Cheetah Print" /></a></div>
                    <div class="c_r_c_li_info">
                        <a href="#" title="Xinh tươi cùng gió"><h1>Blue Cheetah Print</h1></a>
                        <a href="#" title="Lyzmary"><h2>Lyzmary</h2></a>
                        <p><span class="sprites like_icon"></span>322</p>
                        <p><span class="sprites collection_icon"></span>16 ảnh</p>
                    </div>
                </div>
                <div class="c_r_c_li">
                    <div class="c_r_c_li_thumb"><a href="collection.html" title="Sea side strolling "><img src="<?php echo Yii::app()->baseUrl . '/images/demo/collect_3.jpg'; ?>" border="0" title="Sea side strolling" alt="Sea side strolling" /></a></div>
                    <div class="c_r_c_li_info">
                        <a href="#" title="Sea side strolling"><h1>Sea side strolling</h1></a>
                        <a href="#" title="Lyzmary"><h2>Lyzmary</h2></a>
                        <p><span class="sprites like_icon"></span>322</p>
                        <p><span class="sprites collection_icon"></span>16 ảnh</p>
                    </div>
                </div>
                <div class="c_r_c_li">
                    <div class="c_r_c_li_thumb"><a href="collection.html" title="WHITE PRETTY SANDALS & SKORTS"><img src="<?php echo Yii::app()->baseUrl . '/images/demo/collect_4.jpg'; ?>" border="0" title="WHITE PRETTY SANDALS & SKORTS" alt="WHITE PRETTY SANDALS & SKORTS" /></a></div>
                    <div class="c_r_c_li_info">
                        <a href="#" title="WHITE PRETTY SANDALS & SKORTS"><h1>WHITE PRETTY SANDALS & SKORTS</h1></a>
                        <a href="#" title="Lyzmary"><h2>Lyzmary</h2></a>
                        <p><span class="sprites like_icon"></span>322</p>
                        <p><span class="sprites collection_icon"></span>16 ảnh</p>
                    </div>
                </div>
            </div>
            <!-- / collect -->

            <?php
            if ($users && sizeof($users) > 0) {
                ?>
                <!-- may know -->
                <div class="col_right_people">
                    <h1>Bạn đã quen chưa?</h1>
                    <h2>Họ là những người cùng sở thích với bạn</h2>
                    <div class="content">
                        <?php
                        foreach ($users as $u) {
                            ?>
                            <div class="c_r_p_li">
                                <div class="d_avatar mr10 fll"><a href="<?php echo Yii::app()->createUrl('user/view', array('username' => $u->username)); ?>"><img border="0" src="<?php echo Yii::app()->baseUrl . '/upload/user/' . $u->id . '/avatar/' . $u->avatar; ?>" class="d_avatar" /></a></div>
                                <div class="c_r_p_li_info">
                                    <a href="<?php echo Yii::app()->createUrl('user/view', array('username' => $u->username)); ?>" class="member_name"><?php echo $u->fullname; ?></a>
                                    <p>232 người theo dõi</p>
                                    <p>Bộ sưu tập: 7</p>
                                </div>
                                <a id="user_<?php echo $u->id; ?>" onclick="return follow(<?php echo $u->id; ?>);" href="#" class="btn_follow">Theo dõi</a>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            <?php } ?>

            <!-- / may know -->

        </div>
        <!-- / col right -->
        <div class="clr"></div>
        <!-- end view -->
    </div>
</div>
<!-- main home -->




